import { createI18n } from 'vue-i18n';
import sysZhCn from './sys/zh-cn';
import sysEn from './sys/en';
import productsZhCn from '@/i18n/products/zh-cn';
import productsEn from '@/i18n/products/en';
import deviceZhCn from '@/i18n/device/zh-cn';
import deviceEn from '@/i18n/device/en';
import timeEn from '@/i18n/time/en';
import timeZhCn from '@/i18n/time/zh-cn';
import buttonsEn from '@/i18n/buttons/en';
import buttonszhCn from '@/i18n/buttons/zh-cn';
import syslogEn from '@/i18n/syslog/en';
import syslogZhCn from '@/i18n/syslog/zh-cn';
import menuEn from '@/i18n/menu/en';
import menuZhCn from '@/i18n/menu/zh-cn';
import alertEn from '@/i18n/alerts/en';
import alertzhCn from '@/i18n/alerts/zh-cn';
import clusterEn from '@/i18n/clusters/en';
import clusterZhCn from '@/i18n/clusters/zh-cn';
import datacenterEn from '@/i18n/datacenter/en';
import datacenterZhCn from '@/i18n/datacenter/zh-cn';
import ConfigsEn from '@/i18n/configs/en';
import ConfigszhCn from '@/i18n/configs/zh-cn';

import { useAppStoreHook } from "@/store/modules/app";
import { App } from 'vue';

const pureApp = useAppStoreHook();
console.log(pureApp.globalI18n)
export const i18n = createI18n({
  silentTranslationWarn: true,
  missingWarn: false,
  silentFallbackWarn: true,
  fallbackWarn: false,
  legacy: false,
  locale: pureApp.globalI18n == "en" ? "en" : "zh-cn",
  messages: {
    'zh-cn': {
      ...sysZhCn,
      ...productsZhCn,
      ...deviceZhCn,
      ...timeZhCn,
      ...buttonszhCn,
      ...syslogZhCn,
      ...menuZhCn,
      ...alertzhCn,
      ...clusterZhCn,
      ...datacenterZhCn,
      ...ConfigszhCn,
    },
    en: {
      ...sysEn,
      ...productsEn,
      ...deviceEn,
      ...timeEn,
      ...buttonsEn,
      ...syslogEn,
      ...menuEn,
      ...alertEn,
      ...clusterEn,
      ...datacenterEn,
      ...ConfigsEn,
    }
  }
});
// Uncaught SyntaxError: Must be called at the top of a `setup` 解决这个报错
// setup i18n instance with glob
export const setupI18n = {
  install(app: App) {
    app.use(i18n);
  },
};
